<script language="JavaScript" type="text/javascript">
    function subscribe_newsletter()
    {
       
        var req = null; 
        if(window.XMLHttpRequest)
            req = new XMLHttpRequest(); 
        else if (window.ActiveXObject)
            req  = new ActiveXObject(Microsoft.XMLHTTP); 
        req.onreadystatechange = function()
        { 
                    
            document.getElementById('subscribe_newsletter').innerHTML = "<div align='center'></div>" ;               
            if(req.readyState == 4)
            {
                alert("hi");
                var ajaxDisplay = document.getElementById('subscribe_newsletter');
                ajaxDisplay.innerHTML = req.responseText;
                       
            }  
        };
        
        var my_name = document.getElementById('subscriber_name').value;
        if(my_name=='')
        {
            document.getElementById('cust_error').innerHTML = "Required" ;  
            document.getElementById('subscriber_name').focus();
            return false;
        }
                                    
        var my_email = document.getElementById('subscriber_email').value;
        var atpos=my_email.indexOf("@");
        var dotpos=my_email.lastIndexOf(".");
        if(my_email=='')
        {
            document.getElementById('email_error').innerHTML = "Required" ;  
            document.getElementById('subscriber_email').focus();
            return false;       
        }
        else if (atpos<1 || dotpos<atpos+2 || dotpos+2>=my_email.length|| my_email==' ')
        {
            document.getElementById('email_error').innerHTML = "Not Valid Email" ;  
            document.getElementById('subscriber_email').focus();
            return false;       
        }
                                          
        var queryString =  "my_name=" + my_name + "&my_email=" + my_email;
        req.open("POST", "<?= base_url(); ?>ajax/submit_subscribe_newsletter" , true); 
        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
        req.send(queryString);
       
    } 
</script>
<style type="text/css">
    .error{color:red}
</style>
<div id="inner" >
    <p>
    <div class="bold color_2 " > <h2> <?= $title; ?> </h2> </div> 
    <div class="font_1 color_2"> All Fields are Mandatory. Please fill correct information.</div>
    <span class="error" id="sucess-msg"></span>
</p>

<div class="clear"></div>
<form class="form6" id="subscribe_newsletter" method="post" action="#" style="background-color:honeydew">
    <div class="rowElem">
        <div class="fleft">
            <label><strong>Your Name</strong></label>
            <span class="error"id="cust_error"></span>
            <input name="cus_name" id="subscriber_name" type="text" size="19" style="width: 190px" />
        </div>
        <div class="fleft marg_left">
            <label><strong>Your Email</strong></label>
            <span class="error"id="email_error"></span>
            <input name="cus_email" id="subscriber_email" type="text" size="19" style="width: 190px" />
        </div>                                    
        <div class="clear"></div>        
    </div>
     
    <div class="rowElem">
        <div class="fleft">
            <a onClick="subscribe_newsletter();" class="button_search color_1 bold"><span class="inline-block">Subscribe Now !</span></a>
        </div>
        <div class="clear"></div>
    </div>
</form>
</div>

